' Test ab ...and 1 for the monkey.txt rev for SB.exe convert 2021-02-20
' from ... and 1 for the monkey problem.bas for JB 2.0 b 2018-02-11
' Completely rewritten 2021-02-21. 

people "3
nutStart "100
[
	. /          ... and one for the Monkey
	.
	. / There are ;people; people and 1 monkey on an island.
	. / Yesterday the amount of coconuts they collect is ; nutStart
	' track nut inventory with:
	nutsNow = nutStart
	. / Last night, each person goes to the pile, takes a divy
	. / gives 1 coconut to the monkey and hides the remaining.
	. /  (No coconuts are cut into parts in this problem.)
	.
	p = 0
	monkey = 0
	nutsNow = nutStart
	[
		+= p,1
		Jmp p > People
		divy = Int( nutsNow / People )
		If divy >= 1
			-= nutsNow, divy
			+= monkey, 1
			-= divy,1
		Fi
		+= divy,0
		Set piles, p, divy
		. / For person ;p;/ their pile is ; divy; coconut(s).
	]
	. / So the remaining coconuts after last night is ;nutsNow
	. /                        ... and the monkey has ;monkey
	.
	. / This morning, they give the monkey a coconut and divide 
	. / the remaining pile by number of people, what is the size 
	. / of everyone's pile?
	.
	. / Coconuts starting today is ; nutsNow
	If nutsNow > 0 
		monkey = monkey + 1
		nutsNow = nutsNow -1
	Fi
	divy = Int( nutsNow / People )
	. / So each person gets ; divy;/ more coconuts.
	p = 0
	[ 
		+= p,1
		Jmp p > People
		Get curr, piles, p
		total = curr + divy
		. / Person ;p; had hidden ;curr; and gets ;divy; so has ; total
		-= nutsNow, divy
	]
	. / The monkey has ; monkey;/ coconuts.
	. / There remains ; nutsNow; nuts for this author.
	.
	-= NutStart, 10
	If nutStart > 0 
		Loc 34, 5
		. ZZZ... press any to see day with 10 less coconuts to start
		Zzz
		Cls
	El
		Exit
	Fi
]
. /            Good bye!
End

